package demoMod.nanaki.patches.events.city;

import basemod.ReflectionHacks;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.evacipated.cardcrawl.modthespire.lib.SpireReturn;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.events.city.BackToBasics;
import com.megacrit.cardcrawl.localization.EventStrings;
import demoMod.nanaki.NanakiMod;
import demoMod.nanaki.characters.NanakiCharacter;

public class BackToBasicsPatch {
    public static final String ID = NanakiMod.makeID("Back to Basics");
    private static final EventStrings eventStrings;
    public static final String NAME;
    public static final String[] DESCRIPTIONS;
    public static final String[] OPTIONS;

    @SpirePatch(
            clz = BackToBasics.class,
            method = SpirePatch.CONSTRUCTOR
    )
    public static class PatchConstructor {
        public static void Postfix(BackToBasics event) {
            if (AbstractDungeon.player instanceof NanakiCharacter) {
                event.imageEventText.setDialogOption(OPTIONS[4]);
            }
        }
    }

    @SpirePatch(
            clz = BackToBasics.class,
            method = "buttonEffect"
    )
    public static class PatchButtonEffect {
        public static SpireReturn<Void> Prefix(BackToBasics event, int buttonPressed) {
            if (AbstractDungeon.player instanceof NanakiCharacter) {
                try {
                    Enum screen = ReflectionHacks.getPrivate(event, BackToBasics.class, "screen");
                    if ("INTRO".equals(screen.name()) && buttonPressed == 2) {
                        AbstractDungeon.player.heal(AbstractDungeon.player.maxHealth);
                        event.imageEventText.updateBodyText(DESCRIPTIONS[3]);
                        event.imageEventText.clearAllDialogs();
                        event.imageEventText.setDialogOption(OPTIONS[3]);
                        ReflectionHacks.setPrivate(event, BackToBasics.class, "screen", Enum.valueOf((Class<Enum>) Class.forName("com.megacrit.cardcrawl.events.city.BackToBasics$CUR_SCREEN"), "COMPLETE"));
                        return SpireReturn.Return(null);
                    }
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            }
            return SpireReturn.Continue();
        }
    }

    static {
        eventStrings = CardCrawlGame.languagePack.getEventString(ID);
        NAME = eventStrings.NAME;
        DESCRIPTIONS = eventStrings.DESCRIPTIONS;
        OPTIONS = eventStrings.OPTIONS;
    }
}
